
#include <Windows.h>
#include "screen-bitmap.h"

ScreenBitmap::ScreenBitmap()
{
	hwind = GetDesktopWindow();
	hdc = GetDC(hwind);

	width = GetSystemMetrics(SM_CXSCREEN);
	high = GetSystemMetrics(SM_CYSCREEN);
	int BitsPerPixel = GetDeviceCaps(hdc, BITSPIXEL);
	hdc2 = CreateCompatibleDC(hdc);

	info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	info.bmiHeader.biWidth = width;
	info.bmiHeader.biHeight = high;
	info.bmiHeader.biPlanes = 1;
	info.bmiHeader.biBitCount = 24;
	info.bmiHeader.biCompression = BI_RGB;

	hbitmap = CreateDIBSection(hdc2, &info, DIB_RGB_COLORS, (void**)& data, 0, 0);
	SelectObject(hdc2, hbitmap);
}

ScreenBitmap::~ScreenBitmap()
{
	DeleteObject(hbitmap);
	ReleaseDC(hwind, hdc);
	if (hdc2) {
		DeleteDC(hdc2);
	}
}

void ScreenBitmap::refresh(void)
{
	BitBlt(hdc2, 0, 0, width, high, hdc, 0, 0, SRCCOPY);
}
